package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.domain.SysUserAccount;
import com.ruoyi.system.api.model.LoginUser;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService() {
            @Override
            public R<LoginUser> getUserInfo(String username) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUserList(SysUser user) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            /**
             * 获取对应角色的用户
             *
             * @param roleKey
             * @return
             */
            @Override
            public R<List<SysUser>> getUserListByRoleKey(String roleKey) {
                return R.fail("获取对应角色的用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUserAccount> getUserAccountInfo(SysUserAccount userAccount) {
                return R.fail("获取数据库中微信账号信息失败:" + throwable.getMessage());
            }

//            @Override
//            public R<SysUserAccount> getUserAccountInfo(String wxId) {
//                return R.fail("获取数据库中微信账号信息失败:" + throwable.getMessage());
//            }
//
//            @Override
//            public R<SysUserAccount> getUserAccountInfoByPhone(String phoneNumber) {
//                return R.fail("获取数据库中微信账号信息失败:" + throwable.getMessage());
//            }

            @Override
            public R addUserAccountInfo(SysUserAccount userAccount) {
                return R.fail("插入微信授权信息失败:" + throwable.getMessage());
            }

            @Override
            public R updateUserAccountInfo(SysUserAccount userAccount) {
                return R.fail("更新微信授权信息失败:" + throwable.getMessage());
            }
        };


    }
}
